package com.leven.easyerp.web.action.um;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.leven.easyerp.entity.User;
import com.leven.easyerp.service.UserService;
import com.leven.easyerp.web.BaseAction;

/**
 * 用户管理
 * 
 * @author Leven.Chen
 */
@Results({ @Result(name = UserAction.SUCCESS, location = "/index.action", type = "redirect"),
		@Result(name = UserAction.LOGIN, location = "/login.action", type = "redirect") })
public class UserAction extends BaseAction {
	private static final long serialVersionUID = 138043962576902557L;

	@Autowired
	private UserService userService;

	public String login() {
		System.out.println(userService == null);
		return SUCCESS;
	}

	public String createUser() {
		User user = new User();
		user.setUsername("user1");
		user.setAlias("用户1");
		user.setPassword("123");
		try {
			user = userService.createUser(user);
			System.out.println("创建的用户id为：" + user.getId());
			return SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return LOGIN;
		}
	}
}
